﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using WeatherCN_Data.EntityModle;
using WeatherCN_Data.DAL;
using System.Text;
using System.Text.RegularExpressions;

namespace WeatherCN
{
    /// <summary>
    /// Provide the Weather Data through WebService
    /// </summary>
    [WebService(Namespace = "http://HighYouth.com/WeatherCN")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Data : System.Web.Services.WebService
    {

        [WebMethod]
        public WeatherInfo_Converted GetWeatherInfoByCityID(string aCityID)
        {
            return WeatherDAL.GetDataByCityID(aCityID);
        }

        [WebMethod]
        public string GetLocalCityName(string aStreamParam)
        {
            byte[] unicodeBytes = Convert.FromBase64String(aStreamParam);
            // Perform the conversion from gb2312 encoding to the utf8. 
            byte[] asciiBytes = Encoding.Convert(Encoding.GetEncoding("gb2312"), Encoding.UTF8, unicodeBytes);

            //Regex r = new Regex("(\")([\\u4e00-\\u9fa5]*?)(\"\\);)");

            string tp = Encoding.UTF8.GetString(asciiBytes);

            string[] tpa = tp.Split(new char[] { ','});

            if (tpa[2].ToString().Length > 2)
            {
                return tpa[2].Substring(1, tpa[2].Length - 3);
            }
            else
                return "";
            //Match m = r.Match(tp);
            //return m.Groups[2].Value.Replace("市", "").Replace("县", "").Replace("镇", ""); ;
        }
    }
}
